package com.feidee.fd.sml.algorithm.feature

import com.feidee.fd.sml.algorithm.component.feature.{RFormulaEncoder, RFormulaEncoderParam}
import com.feidee.fd.sml.algorithm.util.{TestingDataGenerator, ToolClass}
import org.scalatest.FunSuite

/**
  * @Author: dongguosheng
  * @Date: 2019/3/22 15:42
  * @Review
  * @Email: guosheng_dong@sui.com
  */
class RFormulaEncoderSuite extends FunSuite {
  val paramStr: String =
  """
    |{
    |	"outputCol": "res",
    | "formula": "clicked ~ country + hour",
    | "preserveCols": "id,clicked,res"
    |}
  """.stripMargin

  val rFormula = new RFormulaEncoder()
  val param: RFormulaEncoderParam = rFormula.parseParam(new ToolClass().encrypt(paramStr))

  test("RFormulaEncoder parameter construction test") {
    assert(param.input_pt == null && param.output_pt == null && "res".equals(param.outputCol) &&
      "clicked ~ country + hour".equals(param.formula) && "id,clicked,res".equals(param.preserveCols)
  )
}

  test("RFormulaEncoder training function test") {
    val testingData = TestingDataGenerator.makeRFormulaData()
    testingData.show()
    val res = rFormula.train(param, testingData).transform(testingData)
    res.show()
    assert(res.schema.length == 4)
  }
}
